const app = getApp();
const imgUrl=app.globalData.imgUrl;
const request = require('../../utils/request.js');
const util = require('../../utils/util.js');
const shareUtil = require('../../utils/shareUtil.js');
let ad = null;

Page({
  /**
   * 页面的初始数据
   */
  data: {
    allTools: [
      {
        title: "图片工具",
        tools: [  {
            toolName: "九宫格切图",
            detail: "cutImage",
            url: "/pages/subimg/cuttingNine/cuttingNine",
            icon: imgUrl+"/images/common/mini/cut9.png",
            color: "#ffffff",
            isHidden: false,
            isNew: false
        },  {
            toolName: "九宫格拼图",
            detail: "cutImage",
            url: "/pages/subimg/connetNine/connetNine",
            icon: imgUrl+"/images/common/mini/photo.png",
            color: "#ffffff",
            isHidden: false,
            isNew: false
        },
        //  {
        //     toolName: "爱心九宫格",
        //     detail: "emoji",
        //     url: "/pages/subimg/axjgg/axjgg",
        //     icon: "/images/common/mini/love.png",
        //     color: "#ffffff",
        //     isHidden: false,
        //     isNew: false
        // },  
        {
            toolName: "二维码生成",
            detail: "Qrcode",
            url: "/pages/subimg/createQrcode/createQrcode",
            icon: imgUrl+"/images/common/mini/scanQrcode.png",
            color: "#ffffff",
            isHidden: false,
            isNew: false
        },{
          toolName: "图片加水印",
          detail: "redBag",
          url: "/pages/subimg/waterMarker/waterMarker",
          icon: imgUrl+"/images/common/mini/warter.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
        } , 
        {
          toolName: "数型文字",
          detail: "redBag",
          url: "/pages/subimg/wordart/wordart",
          icon: imgUrl+"/images/common/mini/shuzi.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
        } ,
        {
          toolName: "图片压缩",
          detail: "yasuo",
          url: "/pages/subimg/yasuo/yasuo",
          icon: imgUrl+"/images/common/mini/pressImg.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
        } ,
        // {
        //     toolName: "支持我们",
        //     detail: "redBag",
        //     url: "/pages/ad/ad",
        //     icon: "/images/common/mini/redbag.svg",
        //     color: "#eeeeee",
        //     isHidden: false,
        //     isNew: false
        // } 
      ]
    }, 
    // {
    //     title: "头像壁纸",
    //     tools: [   {
    //         toolName: "个性头像",
    //         detail: "cutImage",
    //         url: "/pages/subimg/pressImg/pressImg",
    //         icon: "/images/common/mini/photo.png",
    //         color: "#ffffff",
    //         isHidden: false,
    //         isNew: false
    //     }, {
    //         toolName: "精美背景图",
    //         detail: "emoji",
    //         url: "/pages/subimg/emoji/emoji",
    //         icon: "/images/common/mini/back.png",
    //         color: "#ffffff",
    //         isHidden: false,
    //         isNew: true
    //     }, {
    //       toolName: "限量壁纸",
    //       detail: "emoji",
    //       url: "/pages/subimg/emoji/emoji",
    //       icon: "/images/common/mini/bizhi.png",
    //       color: "#ffffff",
    //       isHidden: false,
    //       isNew: true
    //       }
    //   ]
    // },
    {
      title: "学习工具",
      tools: [ 
        {
          toolName: "算数题生成",
          detail: "Suanshu",
          url: "/pages/substudy/suanshu/suanshu",
          icon: imgUrl+"/images/common/mini/suanshu.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
        },
      {
        toolName: "翻译",
        detail: "Translate",
        url: "/pages/substudy/trans/trans",
        icon: imgUrl+"/images/common/mini/trans.png",
        color: "#3871dd",
        isHidden: false,
        isNew: false
      }, 
      {
        toolName: "尺子",
        detail: "Ruler",
        url: "/pages/substudy/ruler/ruler",
        icon: imgUrl+"/images/common/mini/ruler.png",
        color: "#ff4351",
        isHidden: false,
        isNew: false
      },
     
    ]
    },
    {
      title: "生活工具",
      tools: [ 
        {
          toolName: "公交来了",
          detail: "Danmu",
          url: "/pages/sublife/bus/bus",
          icon: imgUrl+"/images/common/mini/bus.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
        },
        {
          toolName: "手持弹幕",
          detail: "Danmu",
          url: "/pages/sublife/bulletchat/bulletchat",
          icon: imgUrl+"/images/common/mini/danmu.png",
          color: "#d5527a",
          isHidden: false,
          isNew: false
      }, {
          toolName: "全屏时钟",
          detail: "Clock",
          url: "/pages/sublife/clock/clock",
          icon: imgUrl+"/images/common/mini/clock.png",
          color: "#0f0e0e",
          isHidden: false,
          isNew: false
      },  
      {
        toolName: "绘画板",
        detail: "Draw",
        url: "/pages/sublife/draw/draw",
        icon: imgUrl+"/images/common/mini/draw.png",
        color: "#ffffff",
        isHidden: false,
        isNew: false
      },{
        toolName: "数字转大写",
        detail: "NumToCase",
        url: "/pages/sublife/numToCase/numToCase",
        icon: imgUrl+"/images/common/mini/num.png",
        color: "#9d4651",
        isHidden: false,
        isNew: false
      },
    ]
    },
    {
      title: "休闲工具",
      tools: [ {
          toolName: "周公解梦",
          detail: "Danmu",
          url: "/pages/subgame/jiemeng/index/index",
          icon: imgUrl+"/images/common/mini/meng.png",
          color: "#0f0e0e",
          isHidden: false,
          isNew: false
      }, {
          toolName: "拼图游戏",
          detail: "Clock",
          url: "/pages/subgame/pintugame/pintugame",
          icon: imgUrl+"/images/common/mini/pin.png",
          color: "#ffffff",
          isHidden: false,
          isNew: false
      },
      {
        toolName: "骰子吹牛皮",
        detail: "dice",
        url: "/pages/subgame/playDice/playDice",
        icon: imgUrl+"/images/common/mini/shaizi.svg",
        color: "blue",
        isHidden: false,
        isNew: false
      },
       {
          toolName: "五子棋",
          detail: "chess",
          url: "/pages/subgame/chess/chess",
          icon: imgUrl+"/images/common/mini/five.png",
          color: "#d36ded",
          isHidden: false,
          isNew: false
      },
    ]
    }
   ],
   advertiseList:[
      {
        adImage:"/images/common/mini/phone.svg"
      }
   ],
    tip: 1,
    choosen: 1,
    autoplay: false,
    indicatorDots: false,
    newFuncName: "",
    index: "",
    searchResult: [],
    isSearchError: false,
    imgUrl:app.globalData.imgUrl,
    
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    wx.createRewardedVideoAd && ((ad = wx.createRewardedVideoAd({
        adUnitId: "adunit-4ebd0ed6279b1eb2"
    })).onLoad(function() {}), 
    ad.onError(function(e) {}), 
    ad.onClose(function(e) {
            e && e.isEnded ? that.unLockNewFunc() : wx.showToast({
            title: "未解锁",
            icon: "none"
        });
    }));
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  goToPage: function(e) {
    var item = e.currentTarget.dataset.item, that = this;
    if(item.isNew ){
      wx.showModal({
        title: "提示",
        confirmText: "去解锁",
        cancelText: "下次一定",
        content: "永久开启新功能需要观看广告并观看完后点击一下广告。",
        success: function(e) {
            if(e.confirm && ad){
              that.setData({
                newFuncName: item.toolName
              })
            }
            ad.show().catch(function() {
              ad.load().then(function() {
                    return ad.show();
              }).catch(function(e) {
                  console.log("激励视频 广告显示失败");
              });
            });
        }
      }) 
    }else{
      wx.navigateTo({
        url: item.url
    });
    }
  },

  tip: function() {
    this.setData({
        tip: 0
    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage:shareUtil.shareConfig,
  onShareTimeline:shareUtil.shareConfig,
})